﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.OA.Interface;
using NetDon.OA.Interface.eLogistics;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Finance
{
    [Navigation("干线流程", "查询每日明细")]

    [Function("eLogistics.PaymentMachineAccountInfoManagement")]
    [PageTabber(Index = 0, NavigateUrl = "~/Finance/PaymentMachineAccountInfoManagement.aspx", Title = "付款台帐管理", Type = typeof(PaymentMachineAccountInfoManagement))]
    [PageTabber(Index = 1, NavigateUrl = "~/Finance/DailyFinancialDetailsQuery.aspx", Title = "查询每日明细", Type = typeof(DailyFinancialDetailsQuery))]
    public partial class DailyFinancialDetailsQuery : NavigationPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                this.txtPaymentOrIncomeDateEnd.Text = DateTime.Now.ToString("yyyy-MM-dd");
                this.txtPaymentOrIncomeDateStart.Text = DateTime.Now.ToString("yyyy-MM-dd");
                ddlCompany.InsertEmptyItem(ListEmptyType.Select);
                if (!this.IsSuperRoles())
                {
                    ddlCompany.SelectedValue = CurrentApplicationContext.CompanyId.ToString();
                    ddlCompany.Enabled = false;
                }
                SearchAndBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            SearchAndBind();
        }



        protected void btnReload_Click(object sender, EventArgs e)
        {
            SearchAndBind();
        }


       private void SearchAndBind()
       {
          if(string.IsNullOrWhiteSpace( this.txtPaymentOrIncomeDateStart.Text) && string.IsNullOrWhiteSpace(this.txtPaymentOrIncomeDateEnd.Text))
          {
              Alert("请输入日期范围！");
              return;
          }
             var service = ServiceContainer.GetService<IMachineAccountService>();
            this.gridOrderList.DataSource = service.SearchMachineAccountDataByCondition(GetSearchCriteira());

            this.gridOrderList.DataBind();
       }

      



        private MachineAccountSearchCriteria GetSearchCriteira()
        {
            var criteria = new MachineAccountSearchCriteria
            {
               
            };
            if (!MiscUtilities.IsNullOrEmpty(ddlCompany.SelectedValue))
            {
                criteria.AreaId = ddlCompany.SelectedValue.ToGuid();
            }

            DateTime? dateStart = null, dateEnd = null;
            if (!string.IsNullOrEmpty(txtPaymentOrIncomeDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtPaymentOrIncomeDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtPaymentOrIncomeDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtPaymentOrIncomeDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.PaymentOrIncomeDate = new Range<DateTime?>(dateStart, dateEnd);
            }

           
            return criteria;

        }

  




    }
}